/** Cluster application **/
/* MPPA headers */
#include <mppaipc.h>
#include <mppa/osconfig.h>
#include "math.h"

int main(int argc, char* argv[]) {
	// get arguments
	int rank = atoi(argv[0]);
    const char *global_sync = argv[1], *results_portal = argv[2];	
	// set mask (e.g. 1000..0) 
	long long mask = (long long)1 << rank;
	// open Wx connectors	
	int global_sync_fd = mppa_open(global_sync, O_WRONLY);
    int results_portal_fd = mppa_open(results_portal, O_WRONLY);
	// contributes to unblock the I/O, writes on sync with the mask value
	mppa_write(global_sync_fd, &mask, sizeof(mask));


// START USER CODE 

    int results;
    int i;
    for (i=10; i<=200; i=i+20) {
        results = usr_main(i);
    }
    
// END USER CODE

	// writes on the portal
	mppa_pwrite(results_portal_fd, &results, sizeof(long int), sizeof(long int)*rank);
}
